<?php
/**
 * 抢购中心管理
 *
 *
 ***/


defined('InShopNC') or exit('Access Invalid!');
/**
 * 抢购中心管理
 * @author Administrator
 *
 */
class groupbuyControl extends BaseSellerControl {
    public function __construct() {
        parent::__construct();
    
        //读取语言包
        Language::read('member_groupbuy');
        //检查抢购功能是否开启
        if (intval(C('groupbuy_allow')) !== 1){
            showMessage(Language::get('groupbuy_unavailable'),'index.php?act=seller_center','','error');
        }
    }
    
    /*
     * 20170103
     * 查看团购商品详情
     */
    //http://localhost/lxs/shop/index.php?act=groupbuy&op=groupbuy_detail&group_id=13
    public function groupbuy_detailOp(){
        //通过id查找相关的拼团详情
        $condition['groupbuy_id']=$_REQUEST['group_id'];
        $groupbuy_model=Model('groupbuy');
        //$field1="groupbuy_id,groupbuy_name,leader_id,start_time,end_time,goods_id,goods_name,upper_limit,buyer_count";
        $groupbuy_detail=$groupbuy_model->getGroupbuyInfo($condition);

        Tpl::output('groupbuy_detail',$groupbuy_detail);
        //所有对应的拼团
        $groupbuy_team_model=Model('groupbuy_team');
        $field="team_id,groupbuy_id,lead_id,lead_name,team_number,start_time,end_time,status";
        $team_list=$groupbuy_team_model->get_team_list($condition,$field);
        Tpl::output('team_list',$team_list);
        /* echo '<pre>';
        var_export($team_list);die; */
        
        Tpl::showpage('store_groupbuy_detail.list');
        
    }
    
    /**
     * 抢购列表
     * 当前团购所有拼团列表
     **/
    public function groupbuy_team_listOp() {
        $model_groupbuy = Model('groupbuy');
        $model_groupbuy_quota = Model('groupbuy_quota');
    
        if (checkPlatformStore()) {
            Tpl::output('isOwnShop', true);
        } else {
            $current_groupbuy_quota = $model_groupbuy_quota->getGroupbuyQuotaCurrent($_SESSION['store_id']);
            Tpl::output('current_groupbuy_quota', $current_groupbuy_quota);
        }
    
        $condition = array();
        $condition['store_id'] = $_SESSION['store_id'];
        if(!empty($_GET['groupbuy_state'])) {
            $condition['state'] = $_GET['groupbuy_state'];
        }
        $condition['groupbuy_name'] = array('like', '%'.$_GET['groupbuy_name'].'%');
    
        if (strlen($groupbuy_vr = trim($_GET['groupbuy_vr']))) {
            $condition['is_vr'] = $groupbuy_vr ? 1 : 0;
            Tpl::output('groupbuy_vr', $groupbuy_vr);
        }
        $groupbuy_list = $model_groupbuy->getGroupbuyExtendList($condition, 10);
    
        Tpl::output('group',$groupbuy_list);
        Tpl::output('show_page',$model_groupbuy->showpage());
        Tpl::output('groupbuy_state_array', $model_groupbuy->getGroupbuyStateArray());
    
        self::profile_menu('groupbuy_list');
        Tpl::showpage('store_groupbuy.list');
    }
    
    
    
}